package com.bawei.mdm2207alast.mine.user

import com.bawei.mdm2207alast.base.BaseViewModel
import com.bawei.mdm2207alast.base.IUiIntent
import com.bawei.mdm2207alast.model.db.UserDao
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

/**
 * 作者：赵亮
 * 时间：2024/12/23 16:02
 * 功能：
 */
@HiltViewModel
class UserViewModel @Inject constructor(private val userDao: UserDao) : BaseViewModel() {
    override fun handIntent(it: IUiIntent) {
        when (it) {
            // 注册
            is UserIntent.RegisterIntent -> {
                // room请求
                roomRequest(flow { emit(userDao.register(it.userEntity)) })
            }
            // 登录
            is UserIntent.LoginIntent -> {
                // room请求
                roomRequest(flow { emit(userDao.login(it.name, it.pass, it.role)) })
            }
        }
    }
}